
export const CrudCMixin = {
  data() {
    return {
      inlineForm: 'InlineForm',
      addItemFunc: (item) => {
        console.log('test')
        return new Promise((resolve, reject) => { })
      }
    }
  },
  methods: {
    /**
     * 
     * @param {string} dataInsight 
     * dataInsight==='dataInsight' 是添加了客户群id， 需要调接口把客户群id存入表中
     */
    handleDoSubmit(dataInsight) {
      const form = this.$refs[this.inlineForm]
      if (!form) return
      form.valid(valid => {
        if (valid) {
          const item = form.obj
          this.addDataInsight(dataInsight, item, () => {
            this.addItemFunc(item).then(data => {
              if (data.code === 0) {
                this.$message.success('添加成功!')
                this.$router.go(-1)
              } else {
                this.$message.error(data.description)
              }
            });

          });

        } else {
          this.$message.error('数据填写错误，请按要求填写!')
        }
      })
    },

    addDataInsight(dataInsight, item, func) {
      // if (dataInsight && dataInsight === 'dataInsight') {
      //   req.post({
      //     url: `${Conf.BASE_SERVER_URL}/mod/remote/dataInsight/insertConfig`,
      //     model: this.getFormData(item),
      //   }).then(addCustomsCode => {
      //     if (addCustomsCode.code === 0) {
      //       func();
      //     } else {
      //       this.$message.error(addCustomsCode.description)
      //     }
      //   })
      // } else {
      //   func();
      // }
    },
    getFormData(item) {
      return {
        customsCode: item.dataInsight,
      };
    }

  }
}
